<!-- 开票信息 -->
<template>
  <div class="card">
    <div class="card-header">
      <div class="card-header--content">
        <div class="common-sub-title">反担保相关信息</div>
        <el-icon class="card-header__icon">
          <icon-ep-circle-plus-filled />
        </el-icon>
      </div>
      <el-button plain @click="handleSave">保存</el-button>
    </div>
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      hide-required-asterisk>
      <div class="card-content" v-for="(dataItem, i) in ruleForm.data" :key="i">
        <el-button type="danger" class="card-content__operate">删除</el-button>
        <el-form-item label="反担保方类型" prop="type">
          <el-select v-model="ruleForm.type" placeholder="请选择" style="width: 100px;">
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-row>
          <el-form-item label="企业名称" :prop="'data.' + i + '.companyName'">
            <el-input v-model.trim="dataItem.companyName" placeholder="请输入企业名称" />
          </el-form-item>
          <el-form-item label="纳税人识别号" :prop="'data.' + i + '.taxpayerNumber'">
            <el-input v-model.trim="dataItem.taxpayerNumber" placeholder="请输入纳税人识别号" />
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="联系方式" :prop="'data.' + i + '.companyPhone'">
            <el-input v-model.trim="dataItem.companyPhone" placeholder="请输入企业联系方式" />
          </el-form-item>
          <el-form-item label="反担保方与项目关系" :prop="'data.' + i + '.relationship'">
            <el-input v-model.trim="dataItem.relationship" placeholder="请输入反担保方与项目关系" />
          </el-form-item>
        </el-row>
        <el-form-item label="房产情况">
          <el-table :data="dataItem.estateData" border size="small" style="width: 600px;">
            <el-table-column label="财产位置" prop="" />
            <el-table-column label="财产面积（m²）" width="160"></el-table-column>
            <el-table-column label="证明材料"></el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="法人身份证">
          <div>
            <el-form-item prop="bidDocumentUrl" style="margin-bottom: 20px;">
              <Upload text="人像面上传" />
            </el-form-item>
            <el-form-item prop="letterUrl">
              <Upload text="国徽面上传" />
            </el-form-item>
          </div>
        </el-form-item>
        <el-form-item label="征信报告" prop="letterUrl">
          <Upload text="报告上传" />
        </el-form-item>
        <el-form-item label="不良记录">
          <el-table :data="dataItem.badRecordData" border size="small" style="width: 600px;">
            <el-table-column label="不良对象" prop="label" width="140" />
            <el-table-column label="命中次数" width="160"></el-table-column>
            <el-table-column label="涉及金额（万元）"></el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="流贷情况">
          <el-table :data="dataItem.situationData" border size="small" style="width: 600px;">
            <el-table-column label="流贷种类" prop="label" width="100" />
            <el-table-column label="涉及金额（万元）" ></el-table-column>
          </el-table>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import Upload from './upload.vue'

// 发票类型
const typeOptions = reactive([
  { label: '企业', value: '1' },
  { label: '个人', value: '2' }
])

const ruleForm = reactive({
  // 相关信息
  data:[
    {
      // 发票类型(企业、个人)
      type: '1',
      // 公司名称
      companyName: '',
      // 税号
      taxpayerNumber: '',
      // 联系方式
      companyPhone: '',
      // 关系
      relationship: '',
      // 房产情况
      estateData: [],
      // 法人身份证人像面
      bidDocumentUrl: '',
      // 法人身份证国徽面
      letterUrl: '',
      // 征信报告
      letterUrl: '',
      // 不良记录
      badRecordData: [
        { label: '五年内逾期' },
        { label: '关注及以上类贷款' },
        { label: '展期贷款' },
        { label: '其他不良' }
      ],
      // 流贷情况
      situationData: [
        { label: '短期' },
        { label: '长期' }
      ]
    }
  ]
})

const rules = reactive({
  type: [{ required: true, message: '请选择发票类型' }],
  companyName: [{ required: true, message: '请输入企业名称' }],
  taxpayerNumber: [{ required: true, message: '请输入纳税人识别号' }],
  companyAddress: [{ required: true, message: '请输入公司地址' }],
  companyPhone: [{ required: true, message: '请输入公司电话' }],
  openName: [{ required: true, message: '请输入开户行名称' }],
  openNumber: [{ required: true, message: '请输入开户行账号' }],
  remark: [{ required: true, message: '请输入备注说明' }],
})

// 表单校验
const ruleFormRef = ref(null)
function validateForm() {
  return new Promise((resolve, reject) => {
    ruleFormRef.value.validate(valid => {
      if (valid) {
        resolve(ruleForm)
      }
    })
  })
}

// 保存
function handleSave(){
  validateForm()
  .then(res=>{
    console.log(res,'保存')
  })
}

defineExpose({
  validateForm
})
</script>

<style lang="scss" scoped>
.card-content{
  padding: 20px;
  border-radius: 10px;
  border: 2px solid #FC7000;
  &__operate{
    float: right;
  }
}

.card-header__icon{
  color: #FC7000;
  font-size: 30px;
  cursor: pointer;
}
</style>
